package com.fzrskj.cloud.free.miniservice.utils;

import ms.core.object.CObject;

import java.util.Map;

/**
 * PriceUtils.
 *
 * @author zj.
 *         Created on 2019/5/29 0029.
 */
public class DiyProductSyncUtils extends CObject {
    /**
     * 开通通知.
     * @param serverCode 服务编码.
     * @param params 参数.
     * @return 结果.
     */
    public Boolean syncOpen (String serverCode, Map<String, Object> params) {
        MiniServiceRequest miniServiceRequest = new MiniServiceRequest();
        Map result = miniServiceRequest.post(serverCode, "/api/business/new", params, Map.class);
        if (null == result) {
            this.setErrCode(miniServiceRequest.getErrCode(), miniServiceRequest.getMsg());
            return false;
        }
        return true;
    }

    /**
     * 续费通知.
     * @param serverCode 服务编码.
     * @param params 参数.
     * @return 结果.
     */
    public Boolean syncRenew (String serverCode, Map<String, Object> params) {
        MiniServiceRequest miniServiceRequest = new MiniServiceRequest();
        Map result = miniServiceRequest.post(serverCode, "/api/business/renew", params, Map.class);
        if (null == result) {
            this.setErrCode(miniServiceRequest.getErrCode(), miniServiceRequest.getMsg());
            return false;
        }
        return true;
    }

    /**
     * 升级通知.
     * @param serverCode 服务编码.
     * @param params 参数.
     * @return 结果.
     */
    public Boolean syncUpgrade(String serverCode, Map<String, Object> params) {
        MiniServiceRequest miniServiceRequest = new MiniServiceRequest();
        Map result = miniServiceRequest.post(serverCode, "/api/business/upgrade", params, Map.class);
        if (null == result) {
            this.setErrCode(miniServiceRequest.getErrCode(), miniServiceRequest.getMsg());
            return false;
        }
        return true;
    }

    /**
     * 删除通知.
     * @param serverCode 服务编码.
     * @param businessId 参数.
     * @return 结果.
     */
    public Boolean syncDelete (String serverCode, String businessId) {
        MiniServiceRequest miniServiceRequest = new MiniServiceRequest();
        Map result = miniServiceRequest.delete(serverCode, "/api/business/" + businessId, Map.class);
        if (null == result) {
            this.setErrCode(miniServiceRequest.getErrCode(), miniServiceRequest.getMsg());
            return false;
        }
        return true;
    }
}
